package frontend

import (
	"blog/service/page"
	"net/http"
	"strconv"

	"github.com/gin-gonic/gin"
)

func IndexHandle(ctx *gin.Context) {
	//页号
	pageId, err := strconv.ParseInt(ctx.Query("page"), 10, 64)
	if err != nil {
		pageId = 1
	}
	if pageId < 1 {
		pageId = 1
	}

	// 使用PS层服务
	indexPageService := page.NewIndexPageService()
	R, err := indexPageService.GetIndexPageData(ctx, pageId)
	if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}

	ctx.HTML(http.StatusOK, "index.html", R)
}
